function getday(){
  console.log(11);
  var timestamp = Date.parse(new Date());
  var date = new Date(timestamp);
  //获取年份  
  var Y =date.getFullYear();
  //获取月份  
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  //获取当日日期 
  var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); 
  console.log(222);
  return Y + '-' + M+ '-' + D;
}
// pages/record/record.js
const t = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    iconsUrl:t.globalData.iconsUrl,
    accountIndex:0,
    accountIndex2:0,
    showbox1:false,
    shopname:'',
    shops:false,
    select1:1,
    select2:1,
    select3:3,
    shoparr: [ // value传给后台的值 ， label页面上显示的文字
      {value:'0', label:'全部门店'},
    ],
    loading:true,
    user_id:'',
    b_id:0,
    car_id:'',
    u_name:'',
    box3show:false,
    change:0,
    page:1,
    total:0,
    canpre:true,
    cannext:true,
    siteparr: [
      {value:'0', label:'全部工位'}
    ],
    id:'',
    site_id:'',
    startime: "",
    endtime: "",
    listData:[
 
    ],
    is_log:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    console.log(options);
    that.cklogin();
    let is_log =0;
    if(options.user_id != undefined){
      is_log =1;
    }
    that.setData({
      car_id:parseInt(options.car_id),
      id:options.user_id,
      is_log
    })
  var timestamp = Date.parse(new Date());
  var date = new Date(timestamp);
  //获取年份  
  var Y =date.getFullYear();
  //获取月份  
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  //获取当日日期 
  var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); 
  //startime:Y + '-' + M+ '-' + D+' 00:00',
  that.setData({
    startime:Y + '-' + M+ '-' + D+' 00:00',
    endtime:Y + '-' + M+ '-' + D+' 23:59'
  })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.get_shops();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading(); 
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    that.get_shops();
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  get_washingLog(){
    var that = this;
    let startime= that.data.startime;
    let endtime= that.data.endtime;
    let id=that.data.id;
    let car_id=that.data.car_id;
    console.log(id);
    if(!id){
      id='';
    }else{
      id=parseInt(id);
    }
    if(!car_id){
      car_id='';
    }else{
      car_id=parseInt(car_id);
    }
    if(!startime && !endtime){
      console.log(1);
      startime='';
      endtime='';
    }
    if(startime){
      startime = new Date(startime.replace(/-/g,"/")).getTime()/1000;
    }else{
      startime = '';
    }
    if(endtime){
      endtime = new Date(endtime.replace(/-/g,"/")).getTime()/1000;
    }else{
      endtime = '';
    }
      t.request('/Merchant/MerchantSide/washingLog',{is_log:that.data.is_log,user_id:that.data.user_id,shop_id:that.data.b_id,id:id,car_id:car_id,site_id:that.data.site_id,startime:startime,endtime:endtime,page:that.data.page},function(e){
        let listData =e.result.data;
        console.log(listData);
        that.setData({
          total_cost:e.result.total_cost,
          total_num:e.result.total_num,
          listData:listData,
          total:e.result.total_page
        })
      })
  },
  doseach(){
    this.get_washingLog();
    this.setData({
      box3show: false,
    })
  },

  cklogin(){
    let user_id=wx.getStorageSync('user_id');
    if(user_id){
      let user=wx.getStorageSync('user');
      this.setData({
        user_id:user_id,
        u_name: user.u_name
       })
    }else{
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
  },
  get_shops(){
    var that = this
    if(wx.getStorageSync('user_id')){
      let b_id=t.globalData.b_id;
      t.request('/Merchant/MerchantSide/storeList',{user_id:that.data.user_id,shop_id:b_id},function(e){
        let list=e.result.list;
        let site=e.result.site;
        that.setData({
          accountIndex:t.globalData.accountIndex,
        })
        if(site.length>1){//多店铺
          let gid=t.globalData.b_id;
          if(gid!=0){
            that.setData({
              b_id:gid,
            })
          }
          let siteparr=[{value:'0', label:'全部工位'},];
          for(let i=0;i<site.length;i++){
            let arr ={};
            arr['value']=site[i].site_id;
            arr['label']=site[i].remark;
            siteparr.push(arr);
          }
          console.log(siteparr);
          that.setData({
            siteparr:siteparr
          })
        }
        if(list.length>1){//多店铺
          let shoparr=[{value:'0', label:'全部门店'},];
          for(let i=0;i<list.length;i++){
            let arr ={};
            arr['value']=list[i].store_id;
            arr['label']=list[i].title;
            shoparr.push(arr);
          }
          console.log(shoparr);
          that.setData({
            shops:true,
            shoparr:shoparr
          })
        }else{
          that.setData({
            shopname:e.result.list[0].title,
            b_id:e.result.list[0].store_id,
          })
        }
        that.get_washingLog();
      })
    }
  },
  input1(e){
    this.setData({
      id:e.detail.value
    })
  },

  onRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading(); 
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    this.get_shops();
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },
  navigate(e){
    let page=e.currentTarget.dataset.page
    let id=e.currentTarget.dataset.id;
    if (page == 1) {
      wx.redirectTo({
        url: '/pages/index/index',
      })
    }else if (page == 2) {
      wx.redirectTo({
        url: '/pages/info/info',
      })
    }else if(page == 3){
      wx.redirectTo({
        url: '/pages/record/record',
      })
    }else if(page == 4){
      wx.redirectTo({
        url: '/pages/shop/shop',
      })
    }else if(page == 5){
      wx.navigateTo({
        url: '/pages/info/info?id='+e.currentTarget.dataset.id,
      })
    }
  },

  bindAccountChange(e){
    console.log('切换改变的值', e.detail.value);
    let bid=this.data.shoparr[e.detail.value];
    console.log(bid.value);
    t.globalData.b_id=bid.value;
    t.globalData.accountIndex=e.detail.value;
    this.setData({
      b_id: bid.value,
      accountIndex:e.detail.value
    })
    this.get_shops();
  },

  bindAccountChange2(e){
    console.log('切换改变的值', e.detail.value);
    let site_id=this.data.siteparr[e.detail.value];
    site_id=site_id.value;
    console.log(site_id);
    this.setData({
        accountIndex2: e.detail.value,
        site_id:site_id
    })
  },
  showbox1(e){
    this.setData({
      showbox1: true
    })
    setTimeout(()=>
    {
      this.setData({
        showbox1: false
      })
    }, 2000)
  },
  loginout(e){
    this.setData({
      showbox1: false
    })
    wx.removeStorageSync("user");
    wx.removeStorageSync("user_id");
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  timeChange1(e) {
    console.log(e)
    this.setData({
      startime: e.detail.dateString,
    })
  },
  timeChange2(e) {
    console.log(e)
    this.setData({
      endtime: e.detail.dateString,
    })
  },
  showbox3(e){
    //let id=e.currentTarget.dataset.id
    this.setData({
      box3show: true,
    })
  },
  close2(e){
    console.log(1);
    this.setData({
      box3show: false
    })
  },
  getList2(e){
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    t.request('/users/Washing_log',{page:this.data.page},function(res){
      if (res.code==200) {
       console.log(res);
       let cannext=false;
       if(res.result.total>that.data.page){
        cannext=true;
      }
       that.setData({
        wash_log:res.result.data,
        total:res.result.total,
        cannext:cannext
      })
      wx.hideLoading({
        success: (res) => {},
      })
      }
    })
  },
  change(e){
    this.setData({
      change:e.currentTarget.dataset.index,
      page:1
    })
    this.get_washingLog();
  },
  gopre(){
    this.setData({
      page:this.data.page-1
    })
    this.get_washingLog();
  },
  gonext(){
    this.setData({
      page:this.data.page+1
    })
    this.get_washingLog();
  },
  gofirst(){
    this.setData({
      page:1
    })
    this.get_washingLog();
  },
  golast(){
    this.setData({
      page:this.data.total
    })
    this.get_washingLog();
  },
})